package com.xuebang.admin.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.xuebang.admin.entity.Operator;

public class BaseController {
	protected Operator currentOperator() {
		ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder
				.getRequestAttributes();
		HttpServletRequest req = attrs.getRequest();
		return (Operator) req.getAttribute("currentOperator");
	}
	
	protected String referer(){
		ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder
				.getRequestAttributes();
		HttpServletRequest req = attrs.getRequest();
		return req.getHeader("Referer");
	}

	protected boolean hasPerm(Long ruleId){
		if(this.currentOperator()!=null && this.currentOperator().hasPerm(ruleId)){
			return true;
		}
		return false;
	}
	
	protected String no_perm_page(){
		ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder
				.getRequestAttributes();
		attrs.getRequest().setAttribute("referer", this.referer());
			return "/account/no_perm";
	}
}
